﻿using AutoMapper;
using MediatR;
using ProduceBasicData.Api.Application.Command.ProductionManage.Plan;
using ProduceBasicData.Domain.ProductionManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.ProductionManage.Plan
{
    public class Plan_SchedulingUpdateCommandHandler : IRequestHandler<Plan_SchedulingUpdateCommand, ApiResult<int>>
    {
        private readonly IBaseRespository<Plan_Scheduling> planrepository;
        private readonly IMapper mapper;

        public Plan_SchedulingUpdateCommandHandler(IBaseRespository<Plan_Scheduling> planrepository, IMapper mapper)
        {
            this.planrepository = planrepository;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(Plan_SchedulingUpdateCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<int>()
            {
                Code = ApiEnum.Success,
                Msg = "修改排班成功"
            };
            var info = mapper.Map<Plan_Scheduling>(request);
            result.Data = await planrepository.Update(info);

            return await Task.FromResult(result);
        }
    }
}
